<template>
    <div>
        <div>
            <el-button type="primary" @click="showDialog('insert')" v-if="menuId==='5189'">发放任务</el-button>
            <el-popover placement="bottom-start" width="1000" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
                <el-form :inline="true" :model="search">
                    <el-form-item label="客户名称">
                        <el-autocomplete  class="inputSuffix"  v-model="search.customerName" :fetch-suggestions="searchAsyncSupplier" placeholder="请输入供应商名称" @select="changeSupplier"></el-autocomplete>
                    </el-form-item>
                    <el-form-item label="单号">
                        <el-input v-model="search.code"></el-input>
                    </el-form-item>
                    <el-button type="primary" @click="searchData" icon="el-icon-search">查询</el-button>
                </el-form>
                <el-button slot="reference" type="primary">查询</el-button>
            </el-popover>
        </div>
        <el-table :data="dataList" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass" v-loading='loading'>
            <el-table-column fixed type="index" label="*"  min-width="40"></el-table-column>
            <el-table-column prop="code" label="单号" sortable width="110"></el-table-column>
            <el-table-column prop="customerName.name" label="客户名称" sortable  min-width="80"></el-table-column>
            <el-table-column prop="machineName.type" label="机器" sortable  min-width="80"></el-table-column>
            <el-table-column prop="phenomenon" label="故障现象" sortable  min-width="80"></el-table-column>
            <el-table-column prop="faultTime" label="故障时间" sortable width="100"></el-table-column>
            <el-table-column prop="bxPerson" label="报账人" sortable  min-width="80"></el-table-column>
            <el-table-column prop="bxPhone" label="报账人电话" sortable  min-width="80"></el-table-column>
            <el-table-column prop="repairerName" label="维修人" sortable  min-width="80"></el-table-column>
            <el-table-column prop="planFinishDate" label="计划完成时间" sortable  width="100"></el-table-column>
            <el-table-column prop="isStart" label="启动" width="60">
               <template  slot-scope="scope">
                    <span :class="scope.row.isStart===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="startDate" label="启动时间" sortable  width="100"></el-table-column>
            <el-table-column prop="beginDate" label="出发时间" sortable  width="100"></el-table-column>
            <el-table-column prop="arriveDate" label="到达时间" sortable  width="100"></el-table-column>
            <el-table-column prop="repairStartTime" label="开始维修时间" sortable  width="100"></el-table-column>
            <el-table-column prop="repairEndTime" label="结束维修时间" sortable width="100"></el-table-column>
            <el-table-column prop="leaveDate" label="离开时间" sortable  width="100"></el-table-column>
            <el-table-column prop="endDate" label="到达公司时间" sortable  width="100"></el-table-column>
            <el-table-column prop="result" label="维修结果" sortable  width="100">
                <template  slot-scope="scope">
                    <span :class="scope.row.result===1?'el-icon-circle-check cl-success':''"></span>
                </template>
            </el-table-column>
            <el-table-column prop="creatorName" label="创建人" sortable width="100"></el-table-column>
            <el-table-column prop="createTime" label="创建时间" sortable  width="100"></el-table-column>
            <el-table-column fixed="right" label="操作"  align="center" min-width="160">
                <template slot-scope="scope">
                     <el-button @click="showDialog('update',scope.row)" type="text" size="small">编辑</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>

         <el-dialog :title="dialog.title" width="90%" top="30px" :visible.sync="dialog.isShow" :close-on-click-modal="false" >
            <el-tabs v-model="activeName" @tab-click="handleClick">
                <el-tab-pane label="任务信息" name="1">
                    <el-form :inline="true" class="demo-form-inline" v-model="formData" label-position="right" label-width="180px">
                    <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                    <el-form-item label="单号">
                        <el-input  v-model="formData.code" :disabled="dialog.disableObj.code"></el-input>
                    </el-form-item>
                    <el-form-item label="客户名称">
                        <el-autocomplete
                            v-model="formData.customerNameName" :fetch-suggestions="querySearchAsync1" placeholder="请输入部件名称"  @select="handleSelect1" :disabled="dialog.disableObj.customer"></el-autocomplete>
                    </el-form-item>
                    <el-form-item label="机器名称" v-if="formData.customerNameName">
                        <el-select v-model="formData.machine"   placeholder="请选择" :disabled="dialog.disableObj.machine">
                            <el-option v-for="item in machineList" :key="item.id" :label="item.type" :value="item.id">
                                <span style="float: left">{{ item.type }}</span>
                                <span style="float: right; color: #aaa; font-size: 12px">{{ item.stationCode }}</span>
                            </el-option>
                        </el-select>
                    </el-form-item>
                    <div>
                        <el-form-item label="故障现象">
                            <el-input  v-model="formData.phenomenon"  type="textarea" style="width: 200px;" :disabled="dialog.disableObj.phenomenon"></el-input>
                        </el-form-item>
                        <el-form-item label="故障时间">
                            <el-date-picker v-model="formData.faultTime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始故障时间" style="width: 200px;" :disabled="dialog.disableObj.faultTime"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="报修人">
                            <el-input  v-model="formData.bxPerson" :disabled="dialog.disableObj.bxPerson"></el-input>
                        </el-form-item>
                        <el-form-item label="报修人联系电话">
                            <el-input  v-model="formData.bxPhone" :disabled="dialog.disableObj.bxPhone"></el-input>
                        </el-form-item>
                    </div>
                    <el-form-item label="维修人">
                        <el-select v-model="formData.repairer"   placeholder="请选择" :disabled="dialog.disableObj.repairer">
                            <el-option v-for="item in allRepairPersons" :key="item.id" :label="item.name" :value="item.id" ></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="计划完成时间">
                        <el-date-picker v-model="formData.planFinishDate" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择计划完成时间" style="width: 200px;" :disabled="dialog.disableObj.planFinishDate"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="创建人" v-if="dialog.title==='编辑任务'">
                        <el-input  v-model="formData.creatorName" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="创建时间" v-if="dialog.title==='编辑任务'">
                        <el-input  v-model="formData.createTime" disabled></el-input>
                    </el-form-item>
                    <h3 class="dialog-plate-title"><span>任务启动</span></h3>
                    <el-form-item label="启动">
                            <el-select v-model="formData.isStart"   placeholder="请选择" :disabled="dialog.disableObj.isStart">
                                <el-option  label="未启动" :value="0"></el-option>
                                <el-option label="启动" :value="1"></el-option>
                            </el-select>
                        </el-form-item>
                    <el-form-item label="启动时间">
                        <el-input  v-model="formData.startTime" disabled></el-input>
                    </el-form-item>
                     <h3 class="dialog-plate-title"><span>维修过程</span></h3>
                     <el-form-item label="出发时间">
                        <el-date-picker v-model="formData.beginDate" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择出发时间" style="width: 200px;" :disabled="dialog.disableObj.beginDate"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="到达时间">
                        <el-date-picker v-model="formData.arriveDate" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择出发时间" style="width: 200px;"  :disabled="dialog.disableObj.arriveDate"></el-date-picker>
                    </el-form-item>
                     <el-form-item label="开始维修时间">
                        <el-date-picker v-model="formData.repairStartTime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始维修时间" style="width: 200px;" :disabled="dialog.disableObj.repairStartTime"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="结束维修时间">
                        <el-date-picker v-model="formData.repairEndTime" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始维修时间" style="width: 200px;"  :disabled="dialog.disableObj.repairEndTime"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="离开时间">
                        <el-date-picker v-model="formData.leaveDate" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始维修时间" style="width: 200px;" :disabled="dialog.disableObj.leaveDate"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="到达公司时间">
                        <el-date-picker v-model="formData.endDate" format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择开始维修时间" style="width: 200px;" :disabled="dialog.disableObj.endDate"></el-date-picker>
                    </el-form-item>
                    <el-form-item label="维修结果">
                        <el-select v-model="formData.result"   placeholder="请选择" :disabled="dialog.disableObj.result">
                            <el-option  label="未修好" :value="0"></el-option>
                            <el-option label="修好" :value="1"></el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
                <div style="text-align: center">
                    <el-button @click="submitList" type="primary">确 定</el-button>
                </div>
            </el-tab-pane>
            <el-tab-pane label="物料输入" name="2" v-if="menuId!=='5189'">
                <el-button  @click="showDialog1('add')" class="slot-btn-top" type="primary" size="small">领料</el-button>
                <el-table :data="inputMateriel.list" stripe border class="table-index" :max-height="500" style="width: 100%;" :header-cell-style="getRowClass">
                    <el-table-column fixed type="index" label="*" sortable width="40"></el-table-column>
                    <el-table-column prop="nameName" label="物料名称" sortable min-width="120"></el-table-column>
                    <el-table-column prop="code" label="物料条码" sortable width="120"></el-table-column>
                    <el-table-column prop="type" label="物料类型" sortable min-width="120"></el-table-column>
                    <el-table-column prop="batch" label="物料批号" sortable min-width="120"></el-table-column>
                    <el-table-column prop="num" label="物料数量" sortable width="120"></el-table-column>
                    <el-table-column prop="state" label="物料状态" width="120">
                             <template slot-scope="scope">
                               <el-tag type="success" v-if="scope.row.state==1">正常使用</el-tag>
                               <el-tag type="danger" v-if="scope.row.state==0">不合格</el-tag>
                               <el-tag type="info" v-if="scope.row.state==-1">报废</el-tag>
                            </template>
                        </el-table-column>
                    <el-table-column fixed="right" label="操作" sortable align="center">
                        <template slot-scope="scope">
                            <!-- <el-button @click="showDialog1('checked',scope.row)" type="text" size="small">检验</el-button> -->
                            <el-button @click="deleteInputMateriel(scope.row)" type="text" size="small">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="部件输入" name="3" v-if="menuId!=='5189'">
                <el-button  @click="showDialog1('add')" class="slot-btn-top" type="primary" size="small">领部件</el-button>
                <el-table :data="inputParts.list" stripe border class="table-index" :max-height="500" style="width: 100%;" :header-cell-style="getRowClass">
                    <el-table-column fixed type="index" label="*" sortable width="40"></el-table-column>
                    <el-table-column prop="nameName" label="部件名称" sortable min-width="120"></el-table-column>
                    <el-table-column prop="code" label="部件条码" sortable min-width="120"></el-table-column>
                    <el-table-column prop="type" label="部件类型" sortable min-width="80"></el-table-column>
                    <el-table-column prop="batch" label="部件批号" sortable min-width="80"></el-table-column>
                    <el-table-column prop="num" label="部件数量" sortable width="120"></el-table-column>
                    <!-- <el-table-column prop="state" label="物料状态" max-width="120">
                        <template slot-scope="scope">
                            <el-tag type="success" v-if="scope.row.state==1">正常使用</el-tag>
                            <el-tag type="danger" v-if="scope.row.state==0">不合格</el-tag>
                            <el-tag type="info" v-if="scope.row.state==-1">报废</el-tag>
                        </template>
                    </el-table-column> -->
                    <el-table-column fixed="right" label="操作" sortable align="center" width="100">
                        <template slot-scope="scope">
                            <!-- <el-button @click="showDialog1('checked',scope.row)" type="text" size="small">检验</el-button> -->
                            <el-button @click="deleteInputMateriel(scope.row)" type="text" size="small">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
            <el-tab-pane label="换下的部件" name="4" v-if="menuId!=='5189'">
                <el-button  @click="showDialog1('add')" class="slot-btn-top" type="primary" size="small">新增换下的部件</el-button>
                <el-table :data="removeParts.list" stripe border class="table-index" :max-height="500" style="width: 100%;" :header-cell-style="getRowClass">
                    <el-table-column fixed type="index" label="*" sortable width="40"></el-table-column>
                    <el-table-column prop="nameName" label="部件名称" sortable min-width="120"></el-table-column>
                    <el-table-column prop="code" label="部件条码" sortable min-width="120"></el-table-column>
                    <el-table-column prop="type" label="部件类型" sortable min-width="80"></el-table-column>
                    <el-table-column prop="batch" label="部件批号" sortable min-width="80"></el-table-column>
                    <el-table-column prop="num" label="部件数量" sortable width="120"></el-table-column>
                    <!-- <el-table-column prop="state" label="物料状态" width="120">
                        <template slot-scope="scope">
                            <el-tag type="success" v-if="scope.row.state==1">正常使用</el-tag>
                            <el-tag type="danger" v-if="scope.row.state==0">不合格</el-tag>
                            <el-tag type="info" v-if="scope.row.state==-1">报废</el-tag>
                        </template>
                    </el-table-column> -->
                    <el-table-column fixed="right" label="操作" sortable align="center" width="100">
                        <template slot-scope="scope">
                            <!-- <el-button @click="showDialog1('checked',scope.row)" type="text" size="small">检验</el-button> -->
                            <el-button @click="deleteInputMateriel(scope.row)" type="text" size="small">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </el-tab-pane>
        </el-tabs>
        </el-dialog>
        <el-dialog :title="dialog1.title" width="900px" top="30px" :visible.sync="dialog1.isShow" :close-on-click-modal="false" v-dialogDrag>
            <div :style="dialogHeightPane" v-if="dialog1.title=='领料'">
                <el-form :inline="true" class="demo-form-inline" v-model="dialog1.formData" label-position="right" label-width="180px">
                    <el-form-item label="物料名称">
                        <el-autocomplete v-model="dialog1.formData.nameName" :fetch-suggestions="querySearchAsync2" placeholder="请输入物料名称"  @select="handleSelect2" ></el-autocomplete>
                    </el-form-item>
                    <el-form-item label="物料类型">
                        <el-input  v-model="dialog1.formData.type" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="物料编码">
                        <el-input  v-model="dialog1.formData.code" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="物料批号">
                        <el-input  v-model="dialog1.formData.batch" disabled></el-input>
                    </el-form-item>
                    <el-form-item label="物料数量">
                        <el-input  v-model="dialog1.formData.num" ></el-input>
                    </el-form-item>
                </el-form>
                <div style="text-align: center" slot="footer">
                    <el-button @click="addShRepairMaterial" type="primary">确 定</el-button>
                </div>
            </div>
            <div :style="dialogHeightPane" v-else-if="dialog1.title=='领部件'">
                <el-form :inline="true" class="demo-form-inline" v-model="dialog1.formData" label-position="right" label-width="180px">
                    <el-form-item label="部件名称">
                        <el-autocomplete v-model="dialog1.formData.nameName" :fetch-suggestions="querySearchAsync3" placeholder="请输入部件名称"  @select="handleSelect3" ></el-autocomplete>
                    </el-form-item>
                </el-form>
                <div style="text-align: center" slot="footer">
                    <el-button @click="addShRepairMaterial" type="primary">确 定</el-button>
                </div>
            </div>
            <div :style="dialogHeightPane" v-else-if="dialog1.title=='新增换下的部件'">
                <el-form :inline="true" class="demo-form-inline" v-model="dialog1.formData" label-position="right" label-width="180px">
                    <el-form-item label="部件名称">
                        <el-autocomplete v-model="dialog1.formData.nameName" :fetch-suggestions="querySearchAsync4" placeholder="请输入部件名称"  @select="handleSelect4" ></el-autocomplete>
                    </el-form-item>
                    <el-form-item label="部件类型">
                        <el-input  v-model="dialog1.formData.type"></el-input>
                    </el-form-item>
                    <el-form-item label="部件编码">
                        <el-input  v-model="dialog1.formData.code"></el-input>
                    </el-form-item>
                    <el-form-item label="部件批号">
                        <el-input  v-model="dialog1.formData.batch"></el-input>
                    </el-form-item>
                </el-form>

                <div style="text-align: center" slot="footer">
                    <el-button @click="addShRepairMaterial" type="primary">确 定</el-button>
                </div>
            </div>
            <div class="" :style="dialogHeightPane" v-else>
                 <check-form :data="inputMateriel.checkMaterial.list" @submitHanld="submitHanld" ></check-form>
            </div>
        </el-dialog>
    </div>
</template>
<script>
import postSaleApi from "@/axios/postSale.js"
import cgbHttp from '@/axios/cgbHttp.js'
import checkForm from '@/components/page/companyManage/components/scyb/components/checkForm.vue'
export default {
    name: 'statute-file-parent',
     components:{
        checkForm
    },
    data() {
         let menuId = sessionStorage.getItem('menuId');
      return {
            menuId,
            tableHeight:document.documentElement.clientHeight - 170,
            dialogTableHeight: document.documentElement.clientHeight - 260,
            dialogHeightPane: {
                height: (document.documentElement.clientHeight - 180) + 'px',
                overflowY: 'auto'
            },
            machineList:[],
            search:{
              code:'',
              customer:'',
              customerName:''
            },
            pagination:{
              currentPage:1,
              pageSize:10,
              total:0
            },
            dataList:[],
            loading:false,
            activeName:'1',
            dialog:{
                title:'',
                isShow:false,
                disableObj:{}
            },
            dialog1:{
                title:'',
                isShow:false,
                formData:{}
            },
            formData:{},
            processStateData:[],
            allRepairPersons:[],/**所有维修人员 */
            activeName:'1',
            inputMateriel:{
                list:[],
                checkMaterial:{
                    list:[]
                },
                checkMaterialId:'',
            },
            inputParts:{
                list:[]
            },
            removeParts:{
                list:[]
            },
            allParts:[],
            jqbzPartsAll:[]
      }
    },
     watch:{
        'formData.isStart'(newValue, oldValue){
            let self = this;
            if(newValue===1){
                self.formData.startTime = self.timestampToTime1(new Date(),'yy-mm-dd hh:mm:ss')
            }else{
                 self.formData.startTime =null;
            }
        }
    },
    created(){
        let self = this;
        self.getTableList();
        postSaleApi.shRepairUpkeepPersonsAll().then(res=>{
            self.allRepairPersons= res.content;
        })
    },
    methods:{
        getTableList(){
            let self = this;
            let postData={
                currentPage:self.pagination.currentPage,
                pageSize:self.pagination.pageSize,
                code:self.search.code,
                customer: self.search.customerName===''?null:self.search.customer
            }
            self.loading = true;
            switch(self.menuId){
                case '5189':
                    postData.state=0;
                    break;
                case '5190':
                    postData.state=1;
                    break;
                 case '5191':
                    postData.state=2;
                    break;
            }
            postSaleApi.maintenanceList(postData).then(res=>{
                 self.loading = false;
                self.dataList= res.content.records;
                self.pagination.total =res.content.total;
            },error=>{
                 self.loading = false;
            })

        },
        searchData(){
            this.pagination.currentPage = 1;
            this.getTableList()
        },
        handleSizeChange(size){
            this.pagination.pageSize = size;
            this.getTableList()
        },
        handleCurrentChange(current){
            this.pagination.currentPage = current;
            this.getTableList();
        },
        searchAsyncSupplier(queryString, cb){
           postSaleApi.allShCustomerInfo({name:queryString}).then(res=>{
                res.content.forEach(item=>{
                    item.value = item.name
                })
                cb(res.content);
            })
        },
        changeSupplier(item){
            this.search.customer=item.id;
        },
        createStateFilter(queryString) {
            return (state) => {
                return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) !==-1);
            };
        },
        showDialog(type,row){
            let self = this;
            self.dialog.isShow = true;
            self.dialog.title = type==='insert'?'发布任务':'编辑任务';
             if(row){
                self.machineList[0]= row.machineName;
                row.customerNameName = row.customerName.name
             }

            row.repairer=Number( row.repairer);
            self.formData = type==='insert'?{}:row;
            self.dialog.disableObj={
                code:type==='insert'?false :true,
                customer:type==='insert'?false :true,
                machine:type==='insert'?false :true,
                phenomenon:type==='insert'?false :true,
                faultTime:type==='insert'?false :true,
                bxPerson:type==='insert'?false :true,
                bxPhone:type==='insert'?false :true,
                repairer:type==='insert'?false :true,
                planFinishDate:type==='insert'?false :true,
                isStart:self.menuId==='5189'?false:true,
                beginDate:self.menuId==='5190'?false:true,
                arriveDate:self.menuId==='5190'?false:true,
                repairStartTime:self.menuId==='5190'?false:true,
                repairEndTime:self.menuId==='5190'?false:true,
                leaveDate:self.menuId==='5190'?false:true,
                endDate:self.menuId==='5190'?false:true,
                result:self.menuId==='5190'?false:true
            }
            self.activeName = '1'
        },
        querySearchAsync1(queryString, cb){
            postSaleApi.allShCustomerInfo({name:queryString}).then(res=>{
                res.content.forEach(item=>{
                    item.value = item.name
                })
                cb(res.content);
            })
        },
        handleSelect1(item){
            let self = this;
            self.formData.customer=item.id;
            postSaleApi.machineListBgCid(self.formData.customer).then(res=>{
                self.machineList = res.content;
            })
        },
        querySearchAsync2(queryString, cb){
            let self = this;
            postSaleApi.searchMaterialStock({name:queryString}).then(res=>{
                res.content.forEach(item=>{
                    item.value = item.resourcenameName.name
                })
                cb(res.content);
            })
        },
         handleSelect2(item){
            let self = this;
            self.dialog1.formData.name=item.resourcename;
            self.dialog1.formData.code=item.taskcode;
            self.dialog1.formData.batch=item.batchnums;
            self.dialog1.formData.type=item.resourcenameName.type;
            self.dialog1.formData.kid =item.tid;

        },
         querySearchAsync3(queryString, cb){
            let self = this;
            let results = queryString ?  this.allParts.filter(this.createStateFilter(queryString)) : this.allParts;
            cb(results);
        },
        createStateFilter(queryString) {
            return (state) => {
                return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) !==-1);
            };
        },
         handleSelect3(item){
            let self = this;
            self.dialog1.formData.name = item.partsName;
            self.dialog1.formData.kid = item.id;
        },
         querySearchAsync4(queryString, cb){
            let self = this;
            let results = queryString ?  this.jqbzPartsAll.filter(this.createStateFilter(queryString)) : this.jqbzPartsAll;
            cb(results);
        },
        handleSelect4(item){
            let self = this;
            self.dialog1.formData.name = item.id;
        },
        submitList(){
            let self = this;
            let type = self.dialog.title==='发布任务'?'insert':'update';
            self.formData.beginTime= self.formData.beginTime? self.timestampToTime1(self.formData.beginTime,'yy-mm-dd hh:mm:ss'):null;
            self.formData.endTime= self.formData.endTime? self.timestampToTime1(self.formData.endTime,'yy-mm-dd hh:mm:ss'):null;
            let postData={
                id:self.formData.id,
                code:self.formData.code,
                customer:self.formData.customer,
                machine:self.formData.machine,
                phenomenon:self.formData.phenomenon,
                faultTime:self.formData.faultTime? self.timestampToTime1(self.formData.faultTime,'yy-mm-dd hh:mm:ss'):null,
                bxPerson:self.formData.bxPerson,
                bxPhone:self.formData.bxPhone,
                repairer:self.formData.repairer,
                planFinishDate:self.formData.planFinishDate? self.timestampToTime1(self.formData.planFinishDate,'yy-mm-dd hh:mm:ss'):null,
                isStart:self.formData.isStart,
                beginDate:self.formData.beginDate? self.timestampToTime1(self.formData.beginDate,'yy-mm-dd hh:mm:ss'):null,
                arriveDate:self.formData.arriveDate? self.timestampToTime1(self.formData.arriveDate,'yy-mm-dd hh:mm:ss'):null,
                repairStartTime:self.formData.repairStartTime? self.timestampToTime1(self.formData.repairStartTime,'yy-mm-dd hh:mm:ss'):null,
                repairEndTime:self.formData.repairEndTime? self.timestampToTime1(self.formData.repairEndTime,'yy-mm-dd hh:mm:ss'):null,
                leaveDate:self.formData.leaveDate? self.timestampToTime1(self.formData.leaveDate,'yy-mm-dd hh:mm:ss'):null,
                endDate:self.formData.endDate? self.timestampToTime1(self.formData.endDate,'yy-mm-dd hh:mm:ss'):null,
                result:self.formData.result
            }
            postSaleApi.addMaintenance(type,postData).then(res=>{
                self.dialog.isShow = false;
                self.$message.success(`${self.dialog.title}成功`);
                self.getTableList();
            });

        },
        handleClick(tab, event){
            let self = this;
                switch(self.activeName){
                case '1':
                break;
                case '2':
                   self.inputMaterielList();
                break;
                case '3':
                    self.inputPartsList();
                break;
                case '4':
                    self.removePartsList();
                break;
            }
        },
        inputMaterielList(){
            let self = this;
            // 获取输入物料列表
            postSaleApi.maintenanceMaterialList(self.formData.id).then(res=>{
                self.inputMateriel.list = res.content;
            })
        },
        inputPartsList(){
            let self = this;
            // 获取输入物料列表
            postSaleApi.maintenancePartsList(self.formData.id).then(res=>{
                self.inputParts.list = res.content;
            })
        },
        removePartsList(){
            let self = this;
            // 获取输入物料列表
            postSaleApi.maintenanceRemovePartsList(self.formData.id).then(res=>{
                self.removeParts.list = res.content;
            })
        },
        showDialog1(type,row){
          let self = this;
          self.dialog1.isShow = true;
          switch(self.activeName){
                case '2':
                    self.dialog1.title = type==='add'?'领料':'检验';
                    if(type==='add'){
                        self.dialog1.formData={
                                pid:self.formData.id,
                                num:1,
                                batch:'',
                                code:'',
                                type:'',
                                nameName:'',
                                name:''
                            }
                    }else{
                        self.inputMateriel.checkMaterialId=row.id;
                        // self.materialListCheck();
                    }
                  break;
                case '3':
                    self.dialog1.title = type==='add'?'领部件':'检验';
                    if(type==='add'){
                        self.dialog1.formData={
                            pid:self.formData.id,
                            nameName:'',
                            name:'',
                            kid:''
                        }
                    }
                    postSaleApi.shSpacePartsAll().then(res=>{
                        res.content.forEach(item=>{
                            item.value=item.partsNameName.name;
                        })
                        self.allParts=res.content;
                    })
                    break
                case '4':
                    self.dialog1.title = type==='add'?'新增换下的部件':'检验';
                    if(type==='add'){
                        self.dialog1.formData={
                            pid:self.formData.id,
                            nameName:'',
                            name:'',
                            type:'',
                            code:'',
                            batch:''
                        }
                        postSaleApi.selectJqbzParts().then(res=>{
                            res.content.forEach(item=>{
                               item.value = item.name
                            })
                            self.jqbzPartsAll= res.content
                        })

                    }
                    break
          }

        },
        addShRepairMaterial(){
            let self = this;
            let postData=null;
            switch(self.activeName){
                case '2':
                    postSaleApi.maintenanceAddMaterial(self.dialog1.formData).then(res=>{
                        self.$message.success("领料成功");
                        self.dialog1.isShow = false;
                        self.inputMaterielList();
                    })
                break;
                case '3':
                   postData={
                        name:self.dialog1.formData.name,
                        pid: self.dialog1.formData.pid,
                        kid: self.dialog1.formData.kid
                    }
                    postSaleApi.maintenanceAddParts(postData).then(res=>{
                        self.$message.success("领取部件成功");
                        self.dialog1.isShow = false;
                        self.inputPartsList();
                    })
                    break
                case '4':
                    postData={
                        name:self.dialog1.formData.name,
                        pid: self.dialog1.formData.pid,
                        type: self.dialog1.formData.type,
                        code:self.dialog1.formData.code,
                        batch:self.dialog1.formData.batch
                    }
                    postSaleApi.maintenanceAddRemoveParts(postData).then(res=>{
                        self.$message.success("新增换下的部件成功");
                        self.dialog1.isShow = false;
                        self.removePartsList();
                    })
                    break
            }

        },
        deleteInputMateriel(row){
            let self = this;
             this.$confirm('确认删除吗?', '提示', {
                    confirmButtonClass: 'el-button--warning'
                }).then(() => {
                     switch(self.activeName){
                        case '2':
                        postSaleApi.maintenanceDeleteMaterial(row.id).then(res=>{
                                self.inputMaterielList()
                                self.$message.success('删除成功!')
                            },error=>{
                                self.$message.error('删除失败!')
                            })
                        break;
                        case '3':
                            postSaleApi.maintenanceDeleteParts(row.id).then(res=>{
                                self.inputPartsList()
                                self.$message.success('删除成功!')
                            },error=>{
                                self.$message.error('删除失败!')
                            })
                            break
                         case '4':
                            postSaleApi.maintenanceDeleteRemoveParts(row.id).then(res=>{
                                self.removePartsList()
                                self.$message.success('删除成功!')
                            },error=>{
                                self.$message.error('删除失败!')
                            })
                            break
                    }

                })
        },
        submitHanld(data){
            let self = this;
            switch(self.activeName){
                case '2':
                    postSaleApi.updateShRepairMaterialCheck(data).then(res=>{
                        self.dialog1.isShow= false;
                        // self.materialListCheck();
                        self.$message.success("检验记录提交成功!");
                    })
                    break;
                case '3':

            }

        },
        // materialListCheck(){
        //     let self = this;
        //     postSaleApi.shRepairMaterialListCheck(self.inputMateriel.checkMaterialId).then(res=>{
        //         res.content.forEach(el=>{
        //             if(el.type==1){
        //                 el.value=el.value?el.value:'1';
        //             }
        //         })
        //        self.inputMateriel.checkMaterial.list=res.content;
        //     })
        // }
    }
  }
</script>
<style scoped>
.cl-success{
    line-height: 100%;
    font-size:18px;
}
</style>
